package lk.cms.all.dao;

/**
 * @author LK
 * @date 2020/9/5 - 21:04
 */
import java.util.List;

import lk.cms.all.domain.All;
import lk.cms.base.dao.GenericDao;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;



/**
 * all entity's dao interface
 *
 * @author 42276
 *
 */
@Repository
public interface AllDao extends GenericDao<All, Long> {
    /**
     * return an "All" entity by its "username"
     * @param username
     * @return
     */
    @Query(value="  SELECT * FROM `cms`.`t_all` WHERE `username`=?1 ",nativeQuery=true)
    All getByUsername(@Param("username") String username);


    /**
     * 通过id返回一个All对象
     * @param id
     * @return
     */
    @Query(value="  SELECT * FROM `cms`.`t_all` WHERE `id`=?1 ",nativeQuery=true)
    All selectById(@Param("id") Long id);



    /**
     * 返回All实体的全部数据
     * @return
     */
    @Query(value="  SELECT * FROM `cms`.`t_all` ",nativeQuery=true)
    List<All> selectAlls();

    //select COUNT(*) from t_all where username='201808064600';
    @Query(value="  SELECT COUNT(*) FROM `cms`.`t_all` WHERE `username`=?1 ",nativeQuery=true)
    int IfOneExist(@Param("username") String username);
}
